package com.catazy.wanandroid.module_content.ui

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.util.AttributeSet
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import com.catazy.wanandroid.common_base.util.ColorUtil
import com.catazy.wanandroid.common_base.util.SettingUtil
import com.catazy.wanandroid.module_content.R

/**
 * 作者: Tao
 * 日期: 2024/4/12
 * 时间: 10:08
 * 描述: 浏览器容器组件
 */
class WebContainer(
    context: Context,
    attributeSet: AttributeSet? = null,
    def: Int = 0
) :
    CoordinatorLayout(context, attributeSet, def) {

    // 是否是暗黑模式
    private var mDarkTheme: Boolean = false

    // 遮罩颜色
    private var mMaskColor = Color.TRANSPARENT

    init {
        mDarkTheme = SettingUtil.getIsNightMode()
        if (mDarkTheme) {
            mMaskColor = ColorUtil.alphaColor(
                ContextCompat.getColor(
                    getContext(),
                    com.catazy.wanandroid.common_base.R.color.mask_color
                ), 0.6f
            )
        }
    }

    override fun dispatchDraw(canvas: Canvas) {
        super.dispatchDraw(canvas)
        if (mDarkTheme) {
            canvas.drawColor(mMaskColor)
        }
    }
}